import { defineComponent, ref, type PropType } from 'vue'
import AboutView from './AboutView.vue'
export interface OneComExposed {
  func: () => void
  aa: string
}
export const OneCom = defineComponent({
  props: {
    prop1: {
      type: String as PropType<string>,
    },
  },
  expose: ['func', 'aa'],
  emits: {
    click: (
      /**原始的点击事件 */
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      e: MouseEvent,
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      params: {
        /**点击时间 */
        date: string
      },
    ) => true,
  },
  setup(props, ctx) {
    const aa = ref()
    const func = () => {
      console.log('expose出去的方法')
    }
    ctx.expose({
      func,
      aa,
    })
    return () => (
      <div
        onClick={(e) => {
          ctx.emit('click', e, {
            date: new Date().toLocaleString(),
          })
        }}
      >
        {props.prop1}

        <AboutView
          aa={aa.value}
          onUpdate:aa={(val) => {
            aa.value = val
          }}
        ></AboutView>
      </div>
    )
  },
  name: 'OneCom',
})
